﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DevExpressDemos.Controls.GridControl
{
    public partial class Frm_GridControlDemo : DevExpress.XtraEditors.XtraForm
    {
        public Frm_GridControlDemo()
        {
            InitializeComponent();
            SetGridStyle();
            BindGridListData();
        }
        /// <summary>
        /// gridview常用设置
        /// </summary>
        private void SetGridStyle()
        {
            gridView1.OptionsView.ShowGroupPanel = false;   //隐藏分组栏
            gridView1.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Top;//显示新增行
            gridView1.OptionsView.ColumnAutoWidth = false;  //取消列自适应宽度
            gridView1.OptionsView.ShowAutoFilterRow = true; //显示筛选行
            //gridView1.OptionsView.ShowFooter = true;        //显示汇总栏

            //gridView1.OptionsBehavior.ReadOnly = true;      //设置整个表格内容为只读(可复制)
            //gridView1.OptionsBehavior.Editable = false;     //设置整个表格为不可编辑(不可复制)

            //gridView1.OptionsSelection.MultiSelect = true;  //设置为多选
            //gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; //显示多选框
            //gridView1.OptionsSelection.CheckBoxSelectorColumnWidth = 28;  //设置多选框列的长度
        }
        /// <summary>
        /// 绑定List到gridcontrol
        /// </summary>
        private void BindGridListData()
        {
            List<ListData> list = new List<ListData>() {
                new ListData(1,"2",3,false,"5"),
                new ListData(11,"22",33,false,"55"),
                new ListData(11,"222",333,false,"555"),
                new ListData(1111,"2222",3333,false,"5555"),
                new ListData(1111,"2222",33333,false,DateTime.Now)
            };
            gridControl1.DataSource = list;
        }
        /// <summary>
        /// 绑定DataTable到gridcontrol
        /// </summary>
        private void BindGridDtData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("filedname1",typeof(int));
            dt.Columns.Add("filedname2",typeof(string));
            dt.Columns.Add("filedname3",typeof(decimal));
            dt.Columns.Add("filedname4",typeof(bool));
            dt.Columns.Add("filedname5",typeof(object));
            dt.Rows.Add("1", "2", "3", false , "5");
            dt.Rows.Add("11", "22", "33", false, "55");
            dt.Rows.Add("111", "222", "333", false, "555");
            dt.Rows.Add("1111", "2222", "3333", false, "5555");
            dt.Rows.Add("11111", "22222", "33333", false, "55555");
            gridControl1.DataSource = dt;
        }
    }
    public class ListData
    {
        public ListData(int str1 = 0, string str2 = "", decimal str3 = 0, bool str4 = true, object str5 = null)
        {
            filedname1 = str1;
            filedname2 = str2;
            filedname3 = str3;
            filedname4 = str4;
            filedname5 = str5;
        }
        public int filedname1 { get; set; }
        public string filedname2 { get; set; }
        public decimal filedname3 { get; set; }
        public bool filedname4 { get; set; }
        public object filedname5 { get; set; }
    }
}